<template>
  <div class="common-layout">
    <el-container>
      <el-header height="150px">
        <el-row :gutter="20">
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <img src="../img/logo.jpg" style="width: 100px; height: 100px; margin-top: 20px;" />
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <h1>欢迎登录使用后台管理系统</h1>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple"></div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-dropdown>
                <el-button type="primary" id="userOut">
                  {{ tocker.username }}
                  <el-icon class="el-icon--right">
                    <arrow-down />
                  </el-icon>
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item @click="Out">退出</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <!-- 侧边栏 -->
        <el-aside width="200px">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            :unique-opened="true"
            :router="true"
          >
            <el-sub-menu :index="item.path" v-for="(item, key) in menus ">
              <template #title>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item :index="val.path" v-for="(val, keys) in item.children ">
                <template #title>
                  <span>{{ val.authName }}</span>
                </template>
              </el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-aside>
        <!-- 路由显示区域 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router';
import { MyAxios } from '../request/MyAxios';
const router = useRouter()
const tocker = ref('') //存储的本地用户的名字
const menus = ref([])
const Out = function () {
  localStorage.removeItem('userInfo')
  router.push({ path: '/login' })
}
onMounted(async () => {
  //获取去本地的用户名
  tocker.value = JSON.parse(String(localStorage.getItem('userInfo')))
  //渲染侧边栏
  var { data } = await MyAxios.get('/menus')
  menus.value = data.data
})
</script>
<style>
#userOut {
  display: inline-block;
  margin-top: 50px;
}
/* .example-showcase .el-dropdown + .el-dropdown {
  margin-left: 15px;
} */
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 130px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  /* line-height: 0px; */
  height: 800px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  /* line-height: 10px; */
}

/* body > .el-container {
  margin-bottom: 40px;
} */
</style>